
/* File name	: led.c
 * Project 		: BKIT MCR
 * Version 		: 1.0
 * Creation Date: 07/07/2010
 * Tabsize		: 4
 * Author  		: BKIT4U                   
 * Copyright	: (c) 2010 BKIT HARDWARE CLUB - www.bkit4u.com
 * License		: Free.
 * Comments		: 
 * 
 */

/*====================================*/
/*  Include                           */
/*====================================*/
#include <avr/io.h>
#include "led.h"

/*====================================*/
/*	Global Variable Declaration       */
/*====================================*/
unsigned char led_index;
unsigned char led_buffer[4];
unsigned char led7_sig[16] = {/* 0 */ 	0x30,
							  /* 1 */	0xf5,
							  /* 2 */	0x2c,
							  /* 3 */	0x64,
							  /* 4 */	0xe1,
							  /* 5 */	0x62,
							  /* 6 */	0x22,
							  /* 7 */	0xf4,
							  /* 8 */	0x20,
							  /* 9 */	0x60,
							  /* A */	0xa0,
							  /* B */	0x23,
							  /* C */	0x3a,
							  /* D */	0x25,
							  /* E */	0x2a,
							  /* F */	0xaa};

/*====================================*/
/*  Function name: led_init           */
/*  Parameter: null                   */
/*  Description: configure hardware   */
/*               for led function     */
/*====================================*/
void led_init(){
	DDRG |= 0x1f;
	DDRA = 0xff;

	led_index = 0;
	led_buffer[0] = led_buffer[1] = led7_sig[0];
	led_buffer[2] = 0xff;
}

/*====================================*/
/*  Function name: led_mod            */
/*  Parameter: null                   */
/*  Description: output led into led  */
/*             module on MCU circuit  */
/*			    This function is	  */
/*			   called by interrupt	  */
/*			   timer				  */
/*====================================*/
void led_mod(){
	led_index++;
	led_index = led_index % 3;
	
	PORTG |= 0x07;
	PORTG &= ~_BV(led_index);

	PORTA = led_buffer[led_index];
}

/*====================================*/
/*  Function name: led_put            */
/*  Parameter: _val                   */
/*  Description: output _val into led */
/*             module on MCU circuit  */
/*====================================*/
void led_put(unsigned char _val){
	led_buffer[2] = ~_val;
}

/*====================================*/
/*  Function name: led7_putHex        */
/*  Parameter: _val                   */
/*  Description: output _val into led */
/*   7 segment module on MCU circuit  */
/*====================================*/
void led7_putHex(unsigned char _val){
	led_buffer[0] = led7_sig[_val%16];
	led_buffer[1] = led7_sig[_val/16];
}

/*====================================*/
/*  Function name: ext_led_put        */
/*  Parameter: _val                   */
/*  Description: output _val into led */
/*   module on "capacity" circuit     */
/*====================================*/
void ext_led_put(unsigned char _val){
	_val &= 0x03;
	_val <<= 3;
	PORTG &= 0xe7;
	PORTG |= _val;
}



/****************END FILE**************/

